
<template>
    <td><button @click="cz" class="btn btn-danger">重置</button></td>
    <div>
        <h1>新增员工</h1>
        <tbody class="table">
        <tbody>
            <tr>
                <td>img</td>
                <td>
                    <input type="file" @change="upload">
                    <img style="height: 60px;width: 60px;" :src="axios.defaults.baseURL + data.Img">
                </td>
            </tr>
            <tr>
                <td>Uname</td>
                <td>
                    <input type="text" v-model="data.Uname">
                </td>
            </tr>
            <tr>
                <td>注册时间</td>
                <td>
                    <input type="date" v-model="data.DateTime">
                </td>
            </tr>
             <tr>
                <td>密码</td>
                <td>
                    <input type="password" v-model="data.Pwd">
                </td>
            </tr>
            <tr>
                <td>Age</td>
                <td>
                    <input type="text" v-model="data.Age">
                </td>
            </tr>
             <tr>
                <td>身份证号</td>
                <td>
                    <input type="text" v-model="data.SFZH">
                </td>
            </tr>
           <tr>
                <td>性别</td>
                <td>
                    <input v-model="data.Set" type="radio" name="Set" value="男">男
                    <input v-model="data.Set" type="radio" name="Set" value="女">女
                </td>
            </tr>
            <tr>
                <td>Tid</td>
                <td>
                    <select v-model="data.Tid">
                        <option value="0">选择房型</option>
                        <option v-for="d in Bang" :value="d.Tid">{{ d.Tname }}</option>
                    </select>

                </td>
            </tr>
            <tr>
                <td>state</td>
                <td>
                    <input v-model="data.Stare" type="radio" name="Stare" value="2">2
                    <input v-model="data.Stare" type="radio" name="Stare" value="1">1
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <input type="button" class="btn btn-success" value="新增" @click="saveinfo">
                    <a href="/">返回会员列表</a>
                </td>
            </tr>
        </tbody>
        </tbody>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios'
import { ref,onMounted} from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
//上传
const upload = (abc: any) => {
    //取文件  创建表单数据对象 把文件保存到表单数据对象
    let f = abc.target.files[0]
    let fd = new FormData();
    fd.append("file", f);

    axios.post("/api/WJSC/UpLoad", fd).then(res => {
        data.value.Img = res.data;
    })
}
onMounted(()=>{
    bang();
})
const bang=()=>{
    axios.get("/api/User/bang").then(res=>{
        Bang.value=res.data
    })

}
const Bang=ref([{
    "Tid": 0,
    "Tname": "string"
}])
const data = ref({
  "Uname": "",
  "Pwd": "",
  "Set": "",
  "Age": "",
  "SFZH": "",
  "Img": "string",
  "Tid": 0,
  "Stare": 0,
  "IsDelete": false,
  "DateTime":"",
})
const cz=()=> {
      
       data.value.Uname = ''
       data.value.Pwd = ''
       data.value.Set = ''
       data.value.Age = ''
       data.value.SFZH = ''
       data.value.Img = 'string'
       data.value.Tid = 0
       data.value.DateTime = ''
    }
const saveinfo = () => {
    if(data.value.Img=="")
{
    alert("头像不能为空");
    return;
    
}
    if(data.value.Uname=="")
{
    alert("姓名不能为空");
    return;
    
}
 if(data.value.Pwd=="")
{
    alert("密码不能为空");
    return;
    
}
 if(data.value.Age=="")
{
    alert("年龄不能为空");
    return;
    
}
 if(data.value.SFZH=="")
{
    alert("身份证号不能为空");
    return;
    
}
    axios.post('/api/User/tianjia', data.value).then(res => {
        if (res.data > 0) {
            alert("新增成功")
            router.push("/");
        }
        else {
            alert("新增失败...")
        }
    })
}
</script>

<style scoped></style>